<template>
  <div id="created" v-if="myCreated.count != null">
    <div class="item-box">
      <ArtItem
        :artData="item"
        class="art-item"
        v-for="item in myCreated.data"
        :key="item.id"
        :type="'my'"
      />
    </div>
     <div class="pagination" v-if="myCreated.count != 0">
      <el-pagination
        :page-size="pageSize"
        :pager-count="5"
        layout="prev, pager, next"
        :current-page="pageIndex"
        :total="myCreated.count"
        background
        @prev-click="prevPage"
        @next-click="nextPage"
        @current-change="pageChange"
      >
      </el-pagination>
    </div>
    <div class="no-result" v-if="myCreated.count == 0">
      <span>什么都没找到</span>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
import ArtItem from '@/components/ArtItem'
export default {
  name: "MyCreated",
  components:{
    ArtItem
  },
  data() {
    return {
      pageIndex: 1,
      pageSize: 20,
    };
  },
  mounted() {
    this.$store.dispatch("myCreated", {
      pageIndex: this.pageIndex.toString(),
      pageSize: this.pageSize.toString(),
    });
  },
  computed: {
    ...mapState({
      myCreated: (store) => store.user.myCreated,
    }),
  },
  methods:{
    // 上一页
    prevPage() {
      this.pageIndex -= 1;
      this.$store.dispatch("myCreated", {
        pageIndex: this.pageIndex.toString(),
        pageSize: this.pageSize.toString(),
      });
    },
    // 下一页
    nextPage() {
      this.pageIndex += 1;
      this.$store.dispatch("myCreated", {
        pageIndex: this.pageIndex.toString(),
        pageSize: this.pageSize.toString(),
      });
    },

    // 页数改变
    pageChange(page) {
      this.pageIndex = page
      this.$store.dispatch("myCreated", {
        pageIndex: page.toString(),
        pageSize: this.pageSize.toString(),
      });
    },
  }
};
</script>

<style>
</style>